package com.inforich.app.config;

import com.inforich.app.component.LoginInterceptor;
import com.inforich.app.component.LoginUserHandlerMethodArgumentResolver;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器
 *
 * @author HJM
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

  @Autowired
  private LoginInterceptor loginInterceptor;

  private static final String[] EXCLUDE_PATH = {"/h5api/register", "/h5api/login", "/h5api/test",
      "/h5api/profile/**", "/profile/**", "/getPhone", "/h5api/uploadVehicleApproach"};

  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(loginInterceptor).excludePathPatterns(EXCLUDE_PATH)
        .excludePathPatterns("/testCallBack");
    WebMvcConfigurer.super.addInterceptors(registry);
  }

  @Override
  public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
    argumentResolvers.add(new LoginUserHandlerMethodArgumentResolver());
  }
}
